package com.obas.integration.element.telnet.editor;

import com.ease.common.util.Detect;
import com.obas.integration.element.telnet.type.HWPortFeatureType;
import com.obas.model.business.DeviceMacAddress;

public class HWME60TelnetEditor extends AbstractTelnetEditor {

	// ------------------------------------------------------------------------------
	// UserID Username Interface IP address MAC
	// IPv6 address
	// ------------------------------------------------------------------------------
	// 226907 ftth@km56adsl GE1/0/2.21 112.115.238.241 1c6f-6504-a41b
	public DeviceMacAddress editAsText(String text) {

		String userId = formatString(text.substring(0, 10));
		String _interface = formatString(text.substring(34, 49));
		String ipAddress = formatString(text.substring(49, 66));
		String mac = formatString(text.substring(66, 80));

		DeviceMacAddress deviceMacAddress = new DeviceMacAddress();

		deviceMacAddress.setUserId(userId);

		HWPortFeatureType hWPortFeatureType = HWPortFeatureType.getByText(substring(_interface, 0, 2));
		deviceMacAddress.setPortFeatureType(null != hWPortFeatureType ? hWPortFeatureType.getPortFeatureType() : null);

		deviceMacAddress.setMacAddress(asMacAddress(mac));

		// HWMacAddressType hWMacAddressType = HWMacAddressType.getByText(type);
		// deviceMacAddress.setMacAddressType(null != hWMacAddressType ? hWMacAddressType.getMacAddressType() : null);

		deviceMacAddress.setPortCode(_interface);

		return deviceMacAddress;
	}

	public static String substring(String value, int beginIndex, int endIndex) {
		if (Detect.notEmpty(value) && value.length() >= endIndex) {
			return value.substring(beginIndex, endIndex);
		}
		return null;
	}
}
